﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Android_Helper.android
{
    public class AndroidCommonProcess
    {
        public static string PutData2ClearData(string data)
        {
            List<string> list = new List<string>();

            Regex r = new Regex(".+\\.setText\\(", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            MatchCollection matches = r.Matches(data);

            foreach (Match m in matches)
            {
                string value = m.Value.Trim();
                if (list.IndexOf(value) == -1)
                {
                    list.Add(value);
                }
            }

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("private void clearViewData() {");
            stringBuilder.AppendLine("      //清理界面填充数据");
            foreach (string s in list)
            {
                stringBuilder.AppendLine("      "+s+"AppConstant.EMPTY_STRING);");
            }

            list.Clear();
            r = new Regex("ViewUtils\\.setVisible\\(.+", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            matches = r.Matches(data);

            foreach (Match m in matches)
            {
                string value = m.Value.Trim();
                value = value.Substring(0, value.IndexOf(",")+1);
                if (list.IndexOf(value) == -1)
                {
                    list.Add(value);
                }
            }
            stringBuilder.AppendLine("      //将依据条件显示的VIEW置为不可见");
            foreach (string s in list)
            {
                stringBuilder.AppendLine("      " + s+" false);");
            }
            list.Clear();
            //处理图片
            r = new Regex(".+\\.setImageResource\\(", RegexOptions.IgnoreCase | RegexOptions.Multiline);

            matches = r.Matches(data);

            foreach (Match m in matches)
            {
                string value = m.Value.Trim();
                if (list.IndexOf(value) == -1)
                {
                    list.Add(value);
                }
            }
            stringBuilder.AppendLine("      //处理图片");
            foreach (string s in list)
            {
                stringBuilder.AppendLine("      " + s+"0);");
            }
            stringBuilder.AppendLine("}");
            return stringBuilder.ToString();
        }
    }
}
